package spring.boot.btc.model;

import lombok.Data;
import spring.boot.btc.utils.HashUtils;

/**
 * 交易输出---收钱方（只能真人收钱）
 */
@Data
public class TransactionOutput {

    private String hash;

    /**
     * 收钱方公钥
     */
    private String publicKey;

    /**
     * 收钱方公钥hash
     */
    private String address;

    /**
     * 表示收钱方收钱金额
     */
    private long money;

    public TransactionOutput() {
    }

    public TransactionOutput(String publicKey, long money) {
        this.publicKey = publicKey;
        this.money = money;
        initAddress();
        initHash();
    }

    private void initAddress() {
        this.address = HashUtils.sha256(publicKey);
    }

    private void initHash() {
        StringBuilder sb = new StringBuilder();
        sb.append(publicKey);
        sb.append(address);
        sb.append(money);
        this.hash = HashUtils.sha256(sb.toString());
    }

}
